package magicbox;

import javax.swing.JFrame;

/**
 *
 * @author Mikael Köhlmyr | mikael@kohlmyr.com | http://www.kmyr.net
 */
public class Window extends JFrame {

        private final Screen screen;

        public Window(Screen screen, String title) {
                super();
                this.screen = screen;
                this.screen.configure();
                this.screen.update();
                super.add(this.screen);
                super.setTitle(title);
                super.setFocusable(true);
                super.setResizable(false);
                super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                super.pack();
        }
        
        public void go(){
                if(this.screen instanceof LoopingScreen)
                        ((LoopingScreen)this.screen).loop();
        }

        public static Window open(int width, int height, Screen screen, String title) {
                Screen.WIDTH = width;
                Screen.HEIGHT = height;
                Window w = new Window(screen, title);
                try {
                        Thread.sleep(50);
                        w.setVisible(true);
                        return w;
                } catch (InterruptedException ex) {
                        System.exit(0);
                        return null;
                }
        }
}
